package top.kenthan;

import java.util.*;

public class FiveElements {
    static String wuxing = "金水木火土";
    static String tiangan =        "甲乙丙丁戊己庚辛壬癸";
    static String tianganFiveEle = "木木火火土土金金水水";
    static String dizhi =        "子丑寅卯辰巳午未申酉戌亥";
    static String dizhiFiveEle = "水土木木土火火土金金土水";

    public static void main(String[] args) {
        String bazi = "辛丑戊戌庚寅乙丑";
        String[] baziSplit = bazi.split("");

        String[] tianganSplit = tiangan.split("");
        String[] tianganEle = tianganFiveEle.split("");
        String[] dizhiSplit = dizhi.split("");
        String[] dizhiEle = dizhiFiveEle.split("");

        HashMap<String, String> tianganMap = new HashMap<>();
        HashMap<String, String> dizhiMap = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            tianganMap.put(tianganSplit[i], tianganEle[i]);
        }
        for (int i = 0; i < 12; i++) {
            dizhiMap.put(dizhiSplit[i], dizhiEle[i]);
        }

        // 遍历八字奇数位得到天干五行
        HashSet<String> baziTianganWuxings = new HashSet<>();
        for (int i = 0; i < bazi.length(); i += 2) {
            String baziTianganWuxing = tianganMap.get(baziSplit[i]);
            baziTianganWuxings.add(baziTianganWuxing);
        }

        // 得到地支五行
        HashSet<String> baziDizhiWuxings = new HashSet<>();
        for (int i = 1; i < bazi.length(); i += 2) {
            String baziDizhiWuxing = dizhiMap.get(baziSplit[i]);
            baziDizhiWuxings.add(baziDizhiWuxing);
        }

        System.out.println("天干五行：" + baziTianganWuxings);
        System.out.println("地支五行：" + baziDizhiWuxings);

        baziDizhiWuxings.addAll(baziTianganWuxings);
        HashSet<String> baziWuxings = baziDizhiWuxings;
        System.out.println("八字五行：" + baziWuxings);

        String[] wuxingSplit = wuxing.split("");
        HashSet<String> wuxingSet = new HashSet<>();
        for (int i = 0; i < 5; i++) {
            wuxingSet.add(wuxingSplit[i]);
        }
        wuxingSet.removeAll(baziWuxings);
        System.out.println("=========================");
        System.out.println("八字缺少：" + wuxingSet);

    }

}
